package com.yunhe.servlet;

import com.yunhe.enity.User;
import com.yunhe.service.serviceimpl.UserServiceImpl;
import com.yunhe.utils.BaseServlet;
import com.yunhe.utils.JsonUtil;
import com.yunhe.utils.ResultVu;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user")
public class UserServlet extends BaseServlet {
     ResultVu resultVu = null;
     UserServiceImpl userService = new UserServiceImpl();
     public  void  login(HttpServletRequest req, HttpServletResponse resp) throws IOException {

          String username = req.getParameter("username");
          String password = req.getParameter("password");
          User user = userService.login(username,password);

         if (user!=null){
              if (user.getStatus() != 1){
                   resultVu=new ResultVu(500,"此账号因涉黄已被封禁",null);
              }else {
                   if (user.getRole()==1){
                        resultVu= new ResultVu(200,"登陆成功",username);
                   } else {
                        resultVu = new ResultVu(500, "此账号权限不足，不允许登录", null);
                   }
              }

         }else {
              resultVu=new ResultVu(500,"登陆失败",null);
         }
         JsonUtil.objToJson(resultVu,resp);
     }
}
